package com.kcht.itsed.mws.persist.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kcht.itsed.mws.alemodel.ECSpec;
import com.kcht.itsed.mws.extendmodel.jpa.EventCycleSpecEntity;
import com.kcht.itsed.mws.extendmodel.jpa.SpecEntityConverter;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Optional;

/**
 * EC规则持久层
 * @author zhangwenshuo
 *
 */
public interface IEventCycleDao extends BaseMapper<EventCycleSpecEntity> {

	@Select("select * from T_EVENT_CYCLE_SPEC where ECSPEC_NAME=#{specName}")
	@Results(
			@Result(
					column = "EC_SPEC",
					property = "ecSpec",
					javaType = ECSpec.class,
					jdbcType = JdbcType.VARCHAR,
					typeHandler = SpecEntityConverter.class
			)
	)
	Optional<EventCycleSpecEntity> findBySpecName(String specName);

	@Select("select ECSPEC_NAME from T_EVENT_CYCLE_SPEC ")
	List<String> queryEventCycleSpec();

	@Delete("delete from T_EVENT_CYCLE_SPEC where ECSPEC_NAME=#{specName}")
	void dropEventCycleSpec(String specName);


}
